package org.sam.beatles.integrations;

import java.util.Collection;

import org.sam.swing.table.JSTableColumn;
import org.sam.swing.table.JSTableModel;
import org.sam.swing.table.JSTableModelLinster;
import org.sam.swing.table.defaultImpl.JSTableDefaultBuilderImpl;
import org.springframework.data.jpa.repository.JpaRepository;

/**
 * jap数据表格操作对象
 * 
 * @author sam
 *
 * @param <E>
 */
public class JSTableJPABuilderImpl<E> extends JSTableDefaultBuilderImpl<E> {

	private JpaRepository<E, Integer> dao;

	public JpaRepository<E, Integer> getDao() {
		return dao;
	}

	public void setDao(JpaRepository<E, Integer> dao) {
		this.dao = dao;
	}

	/**
	 * jap数据表格操作对象
	 * 
	 * @param cls
	 * @param dao
	 * @param cols
	 */
	public JSTableJPABuilderImpl(Class<E> cls, JpaRepository<E, Integer> dao, JSTableColumn... cols) {
		super(cls, cols);
		this.setDao(dao);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public JSTableModelLinster<Collection<E>> buildModelLinster(JSTableModel<Collection<E>> tableModel)
			throws Exception {
		JSTableModelJPAAdapter<E> adapter = new JSTableModelJPAAdapter<E>(this.getDao());
		tableModel.setTableModelLinster(adapter);
		return adapter;
	}

}
